//package cn.online.zhuanshenben.web;
//
//
//import cn.online.zhuanshenben.entity.Sadmin;
//import cn.online.zhuanshenben.util.RedisTool;
//import cn.online.zhuanshenben.util.SerializeUtil;
//import cn.online.zhuanshenben.vo.Result;
//import com.alibaba.fastjson2.JSON;
//
//import javax.servlet.*;
//import javax.servlet.annotation.WebFilter;
//import javax.servlet.http.HttpServletRequest;
//import java.io.IOException;
//import java.util.Enumeration;
//
///**
// * @author oldliu
// * @since 1.0
// */
//@WebFilter(filterName = "role",urlPatterns = {"*.do","*.cmd"})
//public class RoleFiter implements Filter {
//    @Override
//    public void init(FilterConfig filterConfig) throws ServletException {
//
//    }
//    public void dumphead(HttpServletRequest req){
//        Enumeration<String> er = req.getHeaderNames();
//        while (er.hasMoreElements()){
//            String s = er.nextElement();
//            System.out.println(s+">>>>>>>>>>>>>>>>"+req.getHeader(s));
//        }
//    }
//    @Override
//    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
//
//
//        HttpServletRequest req= (HttpServletRequest) request;
//        dumphead(req);
//        if (req.getMethod().equalsIgnoreCase("options")) {
//            chain.doFilter(request, response);
//            return;
//        }
//
//        String path=req.getServletPath();
//        if(path.startsWith("/upload")||path.startsWith("/login")||path.startsWith("/genCode")){
//            chain.doFilter(request,response);
//            return;
//        }
//        String token=req.getHeader("Authorization");
//        RedisTool r=new RedisTool();
//        try {
//            Sadmin admin = (Sadmin) SerializeUtil.unserialize(r.get_Obj(token));
//
//            if (admin != null) {
//                //刷新对象的存活时间
//                r.expire(token,1800);
//                chain.doFilter(request, response);
//                return;
//            }
//        }catch (Exception e){
//            e.printStackTrace();
//        }finally {
//            r.getJedis().close();
//        }
//        response.setContentType("application/json;charset=utf-8");
//
//        Result result=Result.error("您还没有登录，不能访问");
//        response.getWriter().print(JSON.toJSONString(result));
//    }
//
//    @Override
//    public void destroy() {
//
//    }
//}
